<?php
	include $setupdata['core_dir']."/modules/payment/gateway/hanzaclass.php";
	$hanzaclass = new hanzaclass;
	
	if ($act=="save"){
		$hanza_data = array();
		if (isset($_POST["VK_SND_ID"])) $hanza_data['VK_SND_ID']=$_POST["VK_SND_ID"]; else $hanza_data['VK_SND_ID']="";
		if (isset($_POST["VK_ACC"])) $hanza_data['VK_ACC']=$_POST["VK_ACC"]; else $hanza_data['VK_ACC']="";
		if (isset($_POST["VK_NAME"])) $hanza_data['VK_NAME']=$_POST["VK_NAME"]; else $hanza_data['VK_NAMED']="";
		if (isset($_POST["VK_LANG"])) $hanza_data['VK_LANG']=$_POST["VK_LANG"]; else $hanza_data['VK_LANG']="";
		if (isset($_POST["VK_CURR"])) $hanza_data['VK_CURR']=$_POST["VK_CURR"]; else $hanza_data['VK_CURR']="";
		if (isset($_POST["KEY_PRIV"])) $hanza_data['KEY_PRIV']=$_POST["KEY_PRIV"];	else $hanza_data['KEY_PRIV']="";
		if (isset($_POST["KEY_PUBL"])) $hanza_data['KEY_PUBL']=$_POST["KEY_PUBL"]; else $hanza_data['KEY_PUBL']="";
		if (isset($_POST["VK_PASS"])) $hanza_data['VK_PASS']=$_POST["VK_PASS"]; else $hanza_data['VK_PASS']="";
		if (isset($_POST["PayURL"])) $hanza_data['PayURL']=$_POST["PayURL"]; else $hanza_data['PayURL']="";
		if (isset($_POST["target"])) $hanza_data['target']=$_POST["target"]; else $hanza_data['target']="_hanza";

		if (openssl_get_privatekey($hanza_data['KEY_PRIV'], $hanza_data['VK_PASS']) === false) $err->AddError(26, "payment_hanza");
		if (openssl_get_publickey($hanza_data['KEY_PUBL']) === false) $err->AddError(27, "payment_hanza");

		foreach($hanza_data as $hanza_key=>$hanza_value) {
			if ($hanza_value == "") $err->AddError(25, "payment_hanza");
			else $hanza_data[$hanza_key] = trim($hanza_data[$hanza_key]);
		}
		
		if (isset($_POST["URL_OK"])) $hanza_data['URL_OK']=trim($_POST["URL_OK"]); else $hanza_data['URL_OK']="";
		if (isset($_POST["URL_CANCEL"])) $hanza_data['URL_CANCEL']=trim($_POST["URL_CANCEL"]); else $hanza_data['URL_CANCEL']="";

		$hanza = addslashes(serialize($hanza_data));
		$mysqlclass->mysql_my_query("DELETE FROM `".$setupdata['table_prefix']."local_vars` WHERE 'payment_gateway_hanza'=`name`", __LINE__, __FILE__);
		$mysqlclass->mysql_my_query("INSERT INTO `".$setupdata['table_prefix']."local_vars` (`id`,`name`,`value`) VALUES ('', 'payment_gateway_hanza', '".$hanza."')", __LINE__, __FILE__);
		
		unset($hanza_tmp);
		unset($hanza_data);
		unset($hanza_key);
		unset($hanza);
	} elseif ($act == "return") {
		$res = $hanzaclass->return_order($_POST);
		$data = $paymentclass->get_gateway_data('hanza');
		if (($res == 'pay') && (isset($data['URL_OK'])) && (strlen($data['URL_OK'])>6)) $str = '"'.$data['URL_OK'].'"';			
		elseif (($res == 'notpay') && (isset($data['URL_CANCEL'])) && (strlen($data['URL_CANCEL'])>6)) $str = '"'.$data['URL_CANCEL'].'"';		
		else $str = "window.opener.location.href";
		print_r('
			<script language="javascript1.4" type="text/javascript">
				url = '.$str.';
				window.opener.location.replace(url);
				window.close();
			</script>
		');
		$mysqlclass->close_db();
		die();
	}
?>